<%@ page language="java" contentType="text/html" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <title>用户展示列表页面</title>
    <%@ include file="../../common/jsp/header.jsp" %>
</head>
<body>
<form class="form-horizontal" id="searchForm" action="/sale/query.do">
    <div style="height: 30px"></div>
    <div class="form-group">
        <label for="inputEmail1" class="col-sm-2 control-label">销售组织:</label>
        <div class="col-sm-2">
            <input type="text" class="form-control" id="inputEmail1" placeholder="请点击选择">
        </div>
        <label for="inputEmail2" class="col-sm-2 control-label">客户:</label>
        <div class="col-sm-2">
            <input type="text" class="form-control" id="inputEmail2" placeholder="请输入">
        </div>
        <label class="col-sm-1 control-label">物资:</label>
        <div class="col-sm-2">
            <select class="form-control" id="inputPassword8" onchange="a1()">
            </select>
        </div>
    </div>
    <div class="form-group">
        <label for="inputPassword3" class="col-sm-2 control-label">计价单位:</label>
        <div class="col-sm-2">
            <select class="form-control" id="inputPassword3">
                <option value="千克">千克</option>
                <option value="克">克</option>
                <option value="公斤">公斤</option>
                <option value="斤">斤</option>
                <option value="袋">袋</option>
            </select>
        </div>
        <label class="col-sm-2 control-label">物资分类:</label>
        <div class="col-sm-2">
            <input type="text" class="form-control" id="inputEmail7">
        </div>
        <label for="inputEmail5" class="col-sm-1 control-label">规格:</label>
        <div class="col-sm-2">
            <input type="text" class="form-control" id="inputEmail5">
        </div>
    </div>
    <div class="form-group">
        <label for="inputPassword6" class="col-sm-2 control-label">价格组:</label>
        <div class="col-sm-2">
            <select class="form-control" id="inputPassword6">
                <option>1</option>
                <option>2</option>
                <option>3</option>
                <option>4</option>
                <option>5</option>
            </select>
        </div>
    </div>
    </div>


    <table class="table table-striped table-bordered table-hover table-condensed">
        <thead>
        <tr>
            <th>销售价</th>
            <th>生效日期</th>
            <th>失效日期</th>
            <th>增删行</th>
        </tr>
        </thead>
        <tbody id="tbody1">
        <tr id="row" name="row1">
            <td><input type="text" placeholder="请输入"/></td>
            <td><input type="date" placeholder="请选择"/></td>
            <td><input type="date" placeholder="请选择"/></td>
            <td>222
                <button type="button" class="btn btn-default" aria-label="Left Align" onclick="insertrow()">
                    <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
                </button>
                <button type="button" class="btn btn-default" aria-label="Left Align" >
                    <span class=" glyphicon glyphicon-minus" aria-hidden="true"></span>
                </button>
            </td>
        </tr>
        </tbody>
    </table>
    <button type="button" class="btn btn-primary col-sm-offset-4" id="add" name="/sale/query.do">返回</button>
    <button type="button" class="btn btn-primary col-sm-offset-1">保存</button>
    <button type="button" class="btn btn-primary col-sm-offset-1">保存并提交</button>
</form>
<script type="application/javascript">
    $(function () {
        $.ajax({
            type: "get",
            url: root + "/sale/queryGam.do",
            // dataType: 'json',
            success: function (data) {
                $('#inputPassword8').append('<option value= "全部">' + "全部" + '</option>');
                var num = data.length
                for (var i = 0; i < num; i++) {
                    $('#inputPassword8').append('<option value= data[i]>' + data[i] + '</option>');
                }
            }
        });
    })
</script>
<script type="application/javascript">
    function a1() {
        var a1 = $('#inputPassword8 option:selected').text()
        $.ajax({
            type: "get",
            url: root + "/sale/querySize/" + a1 + ".do",
            // dataType: 'json',
            success: function (size) {
                $('#inputEmail7').attr("value", size.TYPE_NAME)
                $('#inputEmail5').attr("value", size.GAM_SIZE)
            }
        });
    }

    function insertrow() {

        var row = $("#row").clone();    //克隆第一行
        var lastname = $("table tr:last").attr("id");  //得到table里最后一个tr对象的name
        var num = lastname.substr(3, 10);    //截取row后面的数，是字符串
        var num = parseInt(num) + 1;   //把字符串转成int类型+1
        var num = 'row' + num;    //拼接成新的一行的name
        row.attr("id", num);   //设置新的一行的name属性
        // $('row tr[name=num] td:last button:last' ).on("click",".link",function(){
        //     alert(111)
        // });
        $(".table").append(row);   //这一行加到table的最后面

        alert($("tr[id=num] td:last button:last"))

        $("tr[id=num] td:last button:last").css("height","100px")

        // $("tr[name=num] td:last button:last").click(function(num){
        //     alert(111)
        // });

        // $("#tbody1").on('click','tr[name=num] td:last button:last', function (num) {
        //     $("[name=num]").remove();
        // });

        // alert($("tr[name='row1']").attr("name"))

    }


</script>

</body>
</html>